package com.sky.web;

import com.sky.service.ProductSearchService;
import com.sky.vo.SearchParam;
import com.sky.vo.SearchProductResponse;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


@Controller
public class IndexController {

    @Resource
    private ProductSearchService productSearchService;

    @GetMapping("/list.html")
    public String index(SearchParam searchParam, Model model, HttpServletRequest request) {
        String queryString = request.getQueryString();
        searchParam.setOrgRequestUrl(queryString);
        SearchProductResponse searchProductResponses = productSearchService.searchProduct(searchParam);
        model.addAttribute("result", searchProductResponses);
        return "list";
    }
}
